package com.kevin.permission.controller;

import com.kevin.permission.beans.PageQuery;
import com.kevin.permission.common.JsonData;
import com.kevin.permission.param.AclParam;
import com.kevin.permission.service.SysAclService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@Slf4j
@RequestMapping("/sys/acl")
public class SysAclController {

    @Autowired
    private SysAclService sysAclService;

    @RequestMapping("save.json")
    @ResponseBody
    public JsonData saveAcl(AclParam param){
        sysAclService.save(param);
        return JsonData.success();
    }

    @RequestMapping("update.json")
    @ResponseBody
    public JsonData updateAcl(AclParam param){
        sysAclService.update(param);
        return JsonData.success();
    }

    @RequestMapping("page.json")
    @ResponseBody
    public JsonData list(@RequestParam("aclModuleId")Integer aclModuleId, PageQuery pageQuery){
        return JsonData.success(sysAclService.getPageByAclModuleId(aclModuleId,pageQuery));
    }

    // TODO 通过权限获取用户和角色
//    @ResponseBody
//    @RequestMapping("acls.json")
//    public JsonData acls(@RequestParam("aclId") int aclId){
//        Map<String ,Object> map= Maps.newHashMap();
//        List<SysRole> roleList=sysRoleService.getRoleListByAclId(aclId);
//        map.put("roles",roleList);
//        map.put("users",sysRoleService.getUserListByRoleList(roleList));
//        return JsonData.success(map);
//    }
}
